#ifndef __PAGECACHE_H__
#define __PAGECACHE_H__

#include "qSingleton.h"
#include "cachePagemap.h"

class PageCache : public qSingleton<PageCache>
{
    friend class qSingleton<PageCache>;
public:
    //向系统申请Span内存，使用brk
    void* systemAllocPage(size_t pagesize);
    void systemFreePage(void* ptr, size_t pagesize);
    //向系统申请大块内存 大于128k
    // void* systemAllocBigPage(size_t size);
    // void systemFreeBigPage(void* ptr, size_t size);

    qSpan* getSpan(size_t pagenum);
    qSpan* getSpanByPageid(void* start);
    void releaseSpan(qSpan* sp);
private:
    PageCache(){};
    PageCache(const PageCache&){}
    PageCache& operator=(const PageCache&){}

    //基数树，保存页号与地址映射
    pageMap3<PAGEBITS> pagemap_;
    //pageCache中放的也是span但是没有进行切割的span
	//桶中的list并没有赋值
	//只需要知道pageid和页数，就可以知道内存块大小
	//pageid(页号)范围[pageid, pageid + n(页数))
	//最多128页
    spanList page_spanlist_[PAGE_NUM];

    std::recursive_mutex res_mt_;
};


#endif 